<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>2_回调形式的red</title>
  </head>
  <body>
    <!-- 准备好一个容器 -->
    <div id="root"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom 用于支持react操作dom -->
    <script
      type="text/javascript"
      src="../js/react-dom.development.js"
    ></script>
    <!-- 引入babel 将js转换成jsx -->
    <script type="text/javascript" src="../js/babel.min.js"></script>

    <!-- type="text/babel" 表示写的是 jsx 使用babel 翻译 -->
    <script type="text/babel">
        // 1.创建组件
        class MyComponent extends React.Component{
            
            render(){
                return (
                    <div>
                        <input ref={e => this.input1 = e} type="text"/>
                        <button onClick={this.clickAlertData}>点我输出数据</button>
                        <input  ref={e => this.input2 = e} onBlur={this.blurAlertData} type="text" placeholder="失去焦点弹出数据" />
                    </div>
                );
            }

            clickAlertData = ()=>{
                alert(this.input1.value)
            }
            
            blurAlertData = ()=>{
                alert(this.input2.value);
            }


        }

      // 2.渲染页面到元素
      ReactDOM.render(<MyComponent/>, document.getElementById("root"));
    </script>
  </body>
</html>
